﻿package com.bigstar.lolkor;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.google.ads.AdView;

public class ServerStatus extends Activity{
	
    @Override
    protected void onResume() {
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
    	super.onResume();
    }

	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
        ChampionData.load(this);
        ItemData.load(this);
        Rune.load(this);
        this.setContentView(R.layout.server_status);
		if(getIntent().getStringExtra("menual") != null){
	        AdView adview = (AdView)findViewById(R.id.adView);
	        adview.setVisibility(View.GONE);
 			int menual = ChampionData.champions.get(Integer.parseInt(getIntent().getExtras().getString("champid"))).menual;
	        WebView wv = (WebView)findViewById(R.id.webView1);
			wv.setWebViewClient(new WebViewClient(){
	        	@Override
	        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        		// return super.shouldOverrideUrlLoading(view, url);
	        		if(url.length() >= 42 && url.substring(0, 42).equals("http://lol.inven.co.kr/dataninfo/mastery/?")){
	        			Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
	               		startActivity(i);
	               		return true;
	        		}
	        		setTitle(url);
	        		return false;
	        	}
			});
	        WebSettings setting = wv.getSettings();
	        setting.setJavaScriptEnabled(true);
			wv.loadUrl("http://m.inven.co.kr/site/lol/manualtool.php?champnum="+menual+"&nav=lolchamp");
			wv.requestFocus();	
		}else if(getIntent().getStringExtra("counter") != null){
	        AdView adview = (AdView)findViewById(R.id.adView);
	        adview.setVisibility(View.GONE);
 			int counter = ChampionData.champions.get(Integer.parseInt(getIntent().getExtras().getString("champid"))).menual;
	        WebView wv = (WebView)findViewById(R.id.webView1);
			wv.setWebViewClient(new WebViewClient(){
	        	@Override
	        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        		setTitle(url);
	        		return false;
	        	}
			});
	        WebSettings setting = wv.getSettings();
	        setting.setJavaScriptEnabled(true);
			wv.loadUrl("http://m.inven.co.kr/site/lol/counter.php?code="+counter+"&nav=lolchamp");
			wv.requestFocus();	
		}else{
			
	        AdView adview = (AdView)findViewById(R.id.adView);
	        adview.setVisibility(View.GONE);
			WebView wv = (WebView)findViewById(R.id.webView1);
			wv.setWebViewClient(new WebViewClient(){
	        	@Override
	        	public boolean shouldOverrideUrlLoading(WebView view, String url) {
	        		setTitle(url);
	        		return false;
	        	}
			});
	        WebSettings setting = wv.getSettings();
	        setting.setJavaScriptEnabled(true);
			wv.loadUrl("http://m.fow.kr");
			wv.requestFocus();	
			
			/*
	    	Source source = null;
			try {
				source = new Source(new URL("http://lol.inven.co.kr/dataninfo/ladder/index.php?pg=1"));
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	List<Element> atags = source.getAllElements(HTMLElementName.TD);
	    	Element e = null;
	    	String txt = null;
	    	for(int i = 0; i < atags.size(); i++){	
	        	e = (Element) atags.get(i);
	        	txt = e.getContent().toString();
	    		Log.i("w"+i, ""+e.toString());
	    		Log.i("text"+i, ""+txt);
	    	}
	    	*/
		}

	}
	
}
